package com.member.provider.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.member.dto.DealDetail;
import com.member.provider.service.PaymentTransactionService;
import com.member.utils.Result;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther liujian
 * @date 2024/1/4 17:04
 */
@RestController
@RequestMapping("/provider/transaction")
@CrossOrigin
public class PaymentTransactionController {

    @Autowired
    private PaymentTransactionService paymentTransactionService;

    /**
     * @Description TODO
     * @param
     * @retuen result
     * 支付交易管理
     * @date 2024/1/4 17:12
     * @auther 银狐先生
     */
    @PostMapping("/selectTransactionList/{page}/{size}")
    public Result selectTransactionList(@PathVariable Integer page, @PathVariable Integer size, @RequestBody DealDetail dealDetail, @RequestHeader("token") String token
    ){
        //解析token
        Claims claims = Jwts.parser()
                .setSigningKey("xft-ymt")
                .parseClaimsJws(token)
                .getBody();
        LambdaQueryWrapper<DealDetail> queryWrapper = new LambdaQueryWrapper<>();
        if (dealDetail.getPayment()!=null) {
            queryWrapper.eq(DealDetail::getPayment, dealDetail.getPayment());
        }
        return Result.success(paymentTransactionService.page(new Page<>(page, size), queryWrapper));
    }
}
